<template>
<div class="app-container">
  <div style="width: 600px">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="用户名" prop="name">
        <el-input size="small" v-model="form.name" />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input size="small" v-model="form.phone" />
      </el-form-item>
      <el-form-item label="积分" prop="account">
        <el-input size="small" v-model="form.account" />
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" @click="onSubmit('form')">保存</el-button>
        <el-button size="small" @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: '',
        phone: '',
        account: '',
        password: '',
      },
    }
  },
  methods: {
    onSubmit(formName) {
      // this.$message('submit!')
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}
</style>
